package com.lanou3g.demo.base.controller;

import com.lanou3g.demo.base.service.IndexService;
import com.lanou3g.demo.entity.ModuleInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class IndexController {
    @Autowired
    private IndexService indexService;

    @RequestMapping("/index")
    public String view() {
        return "/index";
    }

    @RequestMapping("/index.do")
    public String list(HttpSession session) {
        if (session.getAttribute("admin") != null) {
            List<ModuleInfo> infoList = indexService.moduleList((Long) session.getAttribute("id"));
            session.setAttribute("infoList", infoList);
            session.setMaxInactiveInterval(30 * 60);
            return view();
        }
        return "/login";
    }
}
